windowloads()
getspumber()

getname ()

function outlogin(){outloginfn()}

var divbox = $('.content .type_area')[0]
var page = 1
var flag = true
var pagesize = 12

getData()

function getData(){
    if(!flag){
        return
    }
    flag = false
sendAjax({

url:'goods/api/goodslist/'+page+'/'+pagesize,
success: res => {
   
    let data = res.data.goodslist
    var divs = ``
    for(var item in data){
        var div = `
        <div>
        <a href="detail.html?id=${data[item]._id}" target = "_blank"  id="hrefbox">
            <div id="img-wrapper">
                <img src="${data[item].goodsimg1}" title="${data[item].goodsname}">
            </div>
            <div class="top">
                <p  title="${data[item].goodsname}">${data[item].goodsname}</p>
            </div>
            <div class="buttom">
                <span>￥${parseInt(Math.random()*5000)+1000}</span>
            </div>
        </a>
        </div>   
        `
        divs += div
    }

    let pageHTML = `
        <li onclick=prev()>
            <a href="javascript:void(0);" aria-label="Previous">
                <span aria-hidden="true">&laquo;</span>
            </a>
        </li>`
    let totalPage = res.data.totalPage
        if(totalPage<=5){
            for(var a=1;a<totalPage;a++){
                pageHTML += ` <li onclick = clickpage(${a})  ${page==a? 'class = "active"':''}><a href="javascript:void(0);">${a}</a></li> `
            }
        }else{
            if(page<=3){
                for(var a=1;a<=5;a++){
                    pageHTML +=` <li onclick = clickpage(${a})  ${page==a? 'class = "active"':''}><a href="javascript:void(0);">${a}</a></li> `
                }
            }else if(page>=totalPage-2){
                for(var a=totalPage-4;a<=totalPage;a++){
                    pageHTML += ` <li onclick = clickpage(${a})  ${page==a? 'class = "active"':''}><a href="javascript:void(0);">${a}</a></li> `
                }
            }else{
                for(var a=page-2;a<=page+2;a++){
                    pageHTML += ` <li onclick = clickpage(${a})  ${page==a? 'class = "active"':''}><a href="javascript:void(0);">${a}</a></li> `
                }
            }
        }
    divbox.innerHTML = divs  
        pageHTML += `
        <li onclick = next(${totalPage})>
            <a href="javascript:void(0);" aria-label="Next">
                <span aria-hidden="true">&raquo;</span>
            </a>
        </li>`
        $('#pagination').html(pageHTML)
    flag = true
}
})
}

// 上一页
function prev(){
    if(page<=1){
        return
    }
    page--
    getData()
}
// 下一页
function next(totalPage){
    if(page>=totalPage){
        return
    }
    page++
    getData()
}

// 中间页码点击
function clickpage(a){
    if(page == a) return
    page = a
    getData()
}


